#include "integrator_time.h"

integrator_time_c::
integrator_time_c(float dT)
{
	memset(this, 0, sizeof(integrator_time_c)); 
	delta_time 		= dT;
}

integrator_time_c::
~integrator_time_c()
{}


void 
integrator_time_c::
reset(int rx, int ry, int rz)
{
	if (rx)
	{
		order_1_value.x = initial_value_1.x;
		order_2_value.x = initial_value_2.x;
		count.x			= 0;
	}
	if (ry)
	{
		order_1_value.y = initial_value_1.y;
		order_2_value.y = initial_value_2.y;
		count.y			= 0;
	}
	if (rz)
	{
		order_1_value.z = initial_value_1.z;
		order_2_value.z = initial_value_2.z;
		count.z			= 0;
	}	
}


count_3D_t 
integrator_time_c::
order_1(void)
{	
	if (count.x == 0)
	{
		order_1_value.x = initial_value_1.x;		
		order_2_value.x = initial_value_2.x;
	}
	else
	{
		order_1_value.x += f.x * delta_time;
	}
	
	if (count.y == 0)
	{
		order_1_value.y = initial_value_1.y;
		order_2_value.y = initial_value_2.y;
	}
	else
	{
		order_1_value.y += f.y * delta_time;
	}
	
	if (count.z == 0)
	{
		order_1_value.z = initial_value_1.z;
		order_2_value.z = initial_value_2.z;
	}
	else
	{
		order_1_value.z += f.z * delta_time;
	}
	//printf("++\n");
	count.x++;
	count.y++;
	count.z++;
	return count;
}

	
count_3D_t 
integrator_time_c::
order_2(void)
{	
	order_1();
	
	order_2_value.x += order_1_value.x * delta_time + 0.5 * f.x * pow(delta_time, 2);
	order_2_value.y += order_1_value.y * delta_time + 0.5 * f.y * pow(delta_time, 2);
	order_2_value.z += order_1_value.z * delta_time + 0.5 * f.z * pow(delta_time, 2);
	return count;
}


